package cn.youqu.happy.framework.common.validation;

import cn.hutool.core.util.StrUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class NullOrNotEmptyValidator implements ConstraintValidator<NullOrNotEmpty, Object> {

    @Override
    public void initialize(NullOrNotEmpty annotation) {
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        if (value == null) return true;
        if (value instanceof java.lang.String) {
            return !StrUtil.isEmpty((CharSequence) value);
        } else if (value instanceof java.lang.Number) {
            return ((new Long(String.valueOf(value))) > 0);
        } else {
            return false;
        }
    }

}
